/*
 * @Author: wangdazhuang
 * @Date: 2024-09-12 10:13:12
 * @LastEditTime: 2025-02-18 15:31:02
 * @LastEditors: wangdazhuang
 * @Description: 
 * @FilePath: /pornhub_app/lib/views/main/controllers/main_controller.dart
 */
import 'package:get/get.dart';
import 'package:pornhub_app/services/app_service.dart';
import 'package:pornhub_app/services/user_service.dart';

import '../../../components/announcement/announcement.dart';

class MainController extends GetxController {
  final userService = Get.find<UserService>();
  static const homeIndex = 0;
  static const video = 1;
  static const forbidden = 2;
  static const community = 3;
  static const mine = 4;

  final currentIndex = 0.obs;

  void changeMainTabIndex(int i) {
    final hasForbidden = Get.find<AppService>().hasForbidden;
    if (i != currentIndex.value) {
      currentIndex.value = i;
      if (hasForbidden) {
        ///全部
        if (i == mine) {
          userService.updateAll();
        }
      } else {
        if (i == community) {
          userService.updateAll();
        }
      }
    }
  }

  @override
  void onInit() {
    showAnn();
    // final tab = Get.parameters['tab'] ?? '';
    // final index = switch (tab) {
    //   MainTabNameEnum.home => homeIndex,
    //   MainTabNameEnum.video => video,
    //   MainTabNameEnum.forbidden => forbidden,
    //   MainTabNameEnum.community => community,
    //   MainTabNameEnum.mine => mine,
    //   _ => homeIndex,
    // };
    // changeMainTabIndex(index);
    super.onInit();
  }
}
